package com.stars.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author : Rocks
 * @version : 1.0
 * @date : 2023/2/24 16:10
 * @description : myBatisPlus插件拦截器
 */
@Configuration
public class MyBatisPlusConfig {

    @Value("${star.db}")
    private String db;

    /**
     * mybatis-plus 分页插件拦截器
     * @author : Rocks
     * @date :  2023/2/25 21:49
     * @return MybatisPlusInterceptor
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {

        DbType dbType = DbType.getDbType(db.toLowerCase());
        // 分页拦截
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(dbType));
        
        return interceptor;
    }
}
